<template>
  <div class="import">
    <upload-excel :beforeUpload="beforeUpload" :onSuccess="onSuccess" />
  </div>
</template>

<script>
import { batchEmp } from '@/api/employees'
//导入时间过滤器
import { formatDate } from '@/filters'
export default {
  name: 'import',
  methods: {
    beforeUpload (flie) {
      console.log(flie)
      return true
    },
    //读取上传的文件
    async onSuccess ({ results }) {
      const userRelations = {
        入职日期: 'timeOfEntry',
        手机号: 'mobile',
        姓名: 'username',
        转正日期: 'correctionTime',
        工号: 'workNumber',
        部门: 'departmentName'
      }
      console.log(results)
      // let list = results.map(item => {
      //   let newObj = {}
      //   for (let key in item) {
      //     let engKey = userRelations[key]
      //     if (key == '转正日期' || key == '入职日期') {
      //       let excelTiem = item[key]
      //       let date = new Date((excelTiem - 1) * 24 * 60 * 60 * 1000)
      //       let year = date.getFullYear()
      //       date.setFullYear(year - 70)
      //       let newDate = formatDate(date)
      //       newObj[engKey] = newDate
      //     } else {
      //       newObj[engKey] = item[key]
      //     }
      //   }
      //   return newObj
      // })
      //发请求批量导入员工
      // await batchEmp(list)
      //提示信息
      // this.$message.success('导入成功')
      //返回上一次跳转的页面
      // this.$router.back()
    }
  }
}
</script>

<style></style>
